define(["jquery","bbcare",
    "scprit/nutrition/app/courseLibrary/editCourseLibrary.servers.js",
    "scprit/nutrition/app/courseLibrary/editCourseLibrary.ui.js",
    "scprit/nutrition/app/courseLibrary/editCourseLibrary.event.js"],
    function($,$bb,$servers,$ui,$event){
    var editCourseLibrary = {};

    /**
     * 查询疗程库成功后的回调函数
     */
    var ajaxCourseLibirayCallBack = function(data){
        // libraryId：存在则是点击某个疗程库进来的；不存在则是点击菜单里的编辑疗程库进来的
        var libraryId = $servers.getPageParams();
        $ui.courseLibirayTabInit({
            "id":"courseLibirayTab",
            "list":data,
            "libraryId":libraryId
        });
        $("#courseLibirayTab select").change($event.onCourseChange);
        $("#courseLibirayTab select").change();
    }

    /**
     * 查询食品库成功后的回调函数
     */
    var ajaxFoodlibraryCallBack = function(data){
        $ui.foodLibirayTabInit({
            "id":"foodLibirayTab",
            "list":data,
        });
        $("#foodLibirayTab select").change($event.onfoodLibirayChange);
        $("#foodLibirayTab select").change();
    }

    editCourseLibrary.init = function(){
        var topbars = [
            {
                "icon":"fa fa-times",
                "name":"删除疗程库",
                "callback":$event.onCourseLibirayDel,
                //"params":{"schemeId":schemeId}
            }
        ];
        $bb.toolbar(topbars);
        $servers.ajaxCourseLibiray(ajaxCourseLibirayCallBack);
        $servers.ajaxFoodlibrary(ajaxFoodlibraryCallBack);
    }
    
    return editCourseLibrary;
});